package quick.start.core.connect.request;

import java.io.UnsupportedEncodingException;

import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HTTP;

public class PostRequestWrapper extends RequestWrapper {
	
    @Override
    public HttpUriRequest genRequest() {
        HttpPost request = new HttpPost(url);
        if (null != params) {
            UrlEncodedFormEntity entity = null;
            try {
                entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            request.setEntity(entity);
        }
        return request;
    }

    public static class Builder extends DefaultRequestBuilder {
        @Override
        public RequestWrapper build() {
        	PostRequestWrapper reqWrapper = new PostRequestWrapper();
            preBuild(reqWrapper);
            return reqWrapper;
        }
    }
}
